package youtube_javvidjv;
/**
 * 
 * @author 1210841
 *
 */
public class TestThreadWait {
	public static void main(String[] args) {
		ThreadB b = new ThreadB();
		b.setName("Pedro");
		b.start();
		synchronized (b) {
			try {
				System.out.println(
						Thread.currentThread().getName() + 
						": Espere Pedro completar..."
				);
				b.wait();
			} catch (InterruptedException e) {}//catch
		}//synchronized
		System.out.println(
			Thread.currentThread().getName() + ": finalizado."
		);
		
	}//main
}//class

class ThreadB extends Thread {
	public void run() {
		synchronized (this) {
			for(int i = 0; i <5; i++){
				System.out.println(
					Thread.currentThread().getName() + 
					": Thread Running " + i
				);
			} //for
			notify(); // Notifica thread em espera
		} //synchronized
		System.out.println(
			Thread.currentThread().getName() + ": finalizado."
		);
	} //run
} //class